﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace HuntTheWumpus
{
	public partial class newQuestionButton : Form
	{
		public Trivia trivia;
		TriviaStruct ts;
		int counter;
		int numberCorrect;
		public newQuestionButton()
		{
			
			trivia = new Trivia();
			counter = 0;
			numberCorrect = 0;
			InitializeComponent();

			ts = trivia.getRandomQuestion();
			questionLabel.Text = ts.Question;
			int[] rndQPlacement = { 0, 1, 2, 3 };

			int[] shuffledNumbers = Trivia.shuffle(rndQPlacement);

			randomAnswer1RB.Text = ts.allAnswers[shuffledNumbers[0]];
			randomAnswer2RB.Text = ts.allAnswers[shuffledNumbers[1]];
			randomAnswer3RB.Text = ts.allAnswers[shuffledNumbers[2]];
			randomAnswer4RB.Text = ts.allAnswers[shuffledNumbers[3]];


		}

		private int triviaSequence()
		{
			counter++;

			if ((randomAnswer1RB.Checked && (randomAnswer1RB.Text == ts.CorrectAnswer)) ||
				(randomAnswer2RB.Checked && (randomAnswer2RB.Text == ts.CorrectAnswer)) ||
				(randomAnswer3RB.Checked && (randomAnswer3RB.Text == ts.CorrectAnswer)) ||
				(randomAnswer4RB.Checked && (randomAnswer4RB.Text == ts.CorrectAnswer)))
			{
				numberCorrect++;
				MessageBox.Show("You got it right! You have " + (3 - counter) + " trivia questions left.");
			}

			else
			{
				//incorrect answer
				MessageBox.Show("You got it wrong! You have " + (3 - counter) + " trivia questions left.");
			}

			if (numberCorrect == 2)
			{
				MessageBox.Show("You've answered enough trivia for your prize.");
				// game control will interpret 1 to mean that the player has won
				return 1;
			}
			else if (counter == 3)
			{
				MessageBox.Show("You're out of trivia.");
				// game control will interpret 0 to mean that the player hasn't won
				return 0;
			}
			else
			{
				return 0;
			}
		}

		private void submitAnswerButton_Click_1(object sender, EventArgs e)
		{
			triviaSequence();
		}

		private void button1_Click(object sender, EventArgs e)
		{
			//Get a new question
			//Display on form

			ts = trivia.getRandomQuestion();
			questionLabel.Text = ts.Question;

			//Random randomQuestion = new Random();
			//randomQuestion.Next(1, 4);

			int[] rndQPlacement = { 0, 1, 2, 3 };
			//for (int index = 0; index < rndQPlacement.Length; index++)
			//    rndQPlacement[index] = index;


			//int[] shuffledNumbers = Trivia.shuffle(rndQPlacement);

			randomAnswer1RB.Text = ts.allAnswers[0];
			randomAnswer2RB.Text = ts.allAnswers[1];
			randomAnswer3RB.Text = ts.allAnswers[2];
			randomAnswer4RB.Text = ts.allAnswers[3];

			//randomAnswer1RadioButton.Text = ts.CorrectAnswer;
			//randomAnswer2RadioButton.Text = ts.FalseAnswer1;
			//randomAnswer3RadioButton.Text = ts.FalseAnswer2;
			//randomAnswer4RadioButton.Text = ts.FalseAnswer3;
		}

		
	}
}
